#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    threadA.setMsg("A");
    threadB.setMsg("B");


}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    if(threadA.isRunning())//线程正在运行
    {
        ui->pushButton->setText("startA");
        threadA.stop();//停止线程
        threadA.wait();//等待线程结束
    }else{
        ui->pushButton->setText("stop A");
        threadA.start();
    }
}

void Widget::on_pushButton_2_clicked()
{
    if(threadA.isRunning())//线程正在运行
    {
        ui->pushButton_2->setText("startB");
        threadB.stop();//停止线程
        threadB.wait();//等待线程结束
    }else{
        ui->pushButton_2->setText("stop B");
        threadB.start();
    }
}
